
#include "PCH.h"
#include "MyListener.h"

MyListener::MyListener()
{
	SelectedObject=NULL;
	Scene=NULL;
	Camera=NULL;
}

void MyListener::onMouseButtonDown(PixelToaster::DisplayInterface & display, PixelToaster::Mouse mouse )
{
	if(mouse.buttons.left)
	{
		CRenderableObject* Object = Camera->Camera_GetObject(Scene,int(mouse.x),int(mouse.y));
		if(Object)
		{
			if(SelectedObject)
				SelectedObject->Selected=false;
			Object->Selected=true;
			SelectedObject=Object;
		}
		else
		{
			if(SelectedObject)
				SelectedObject->Selected=false;
		}
	}
}

void MyListener::onKeyDown(PixelToaster::DisplayInterface & display, PixelToaster::Key key )
{

// 	if(key==PixelToaster::Key::OpenBracket)
// 	{
// 		SubSampling--;
// 		if(SubSampling<0)
// 			SubSampling=0;
// 	}
// 	if(key==PixelToaster::Key::CloseBracket)
// 	{
// 		SubSampling++;
// 		if(SubSampling>2)
// 			SubSampling=2;
// 	}


	if(!SelectedObject)
		return;

	if(SelectedObject->GetType()==CRenderableObject::SPHERE)
	{
		if(key==PixelToaster::Key::Left)
		{
			((CSphereObject*)(SelectedObject))->Position.x-=10;
		}

		if(key==PixelToaster::Key::Right)
		{
			((CSphereObject*)(SelectedObject))->Position.x+=10;
		}

		if(key==PixelToaster::Key::Up)
		{
			((CSphereObject*)(SelectedObject))->Position.y+=10;
		}

		if(key==PixelToaster::Key::Down)
		{
			((CSphereObject*)(SelectedObject))->Position.y-=10;
		}

		if(key==PixelToaster::Key::Home)
		{
			((CSphereObject*)(SelectedObject))->Position.z+=10;
		}

		if(key==PixelToaster::Key::End)
		{
			((CSphereObject*)(SelectedObject))->Position.z-=10;
		}

		if(key==PixelToaster::Key::Add)
		{
			((CSphereObject*)(SelectedObject))->Radius+=10;
		}

		if(key==PixelToaster::Key::Subtract)
		{
			((CSphereObject*)(SelectedObject))->Radius-=10;
		}

	}

}
